<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Group Class Reference</title>
    <link rel="stylesheet" type="text/css" href="../../css/jazzy.css" />
    <link rel="stylesheet" type="text/css" href="../../css/highlight.css" />
    <meta charset='utf-8'>
    <script src="../../js/jquery.min.js" defer></script>
    <script src="../../js/jazzy.js" defer></script>
    
  </head>
  <body>
    <a name="//apple_ref/swift/Class/Group" class="dashAnchor"></a>
    <a title="Group Class Reference"></a>
    <header>
      <div class="content-wrapper">
        <p><a href="../../index.html">Venice Docs</a> (100% documented)</p>
        <p class="header-right"><a href="https://github.com/Zewo/Venice"><img src="../../img/gh.png"/>View on GitHub</a></p>
      </div>
    </header>
    <div class="content-wrapper">
      <p id="breadcrumbs">
        <a href="../../index.html">Venice Reference</a>
        <img id="carat" src="../../img/carat.png" />
        Group Class Reference
      </p>
    </div>
    <div class="content-wrapper">
      <nav class="sidebar">
        <ul class="nav-groups">
          <li class="nav-group-name">
            <a href="../../Coroutines.html">Coroutines</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Classes/Coroutine.html">Coroutine</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Classes/Coroutine/Group.html">– Group</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../../Channels.html">Channels</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Classes/Channel.html">Channel</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Classes/Channel.html#/s:CC6Venice7Channel7Sending">– Sending</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Classes/Channel.html#/s:CC6Venice7Channel9Receiving">– Receiving</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../../File Descriptors.html">File Descriptors</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Classes/FileDescriptor.html">FileDescriptor</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Classes/FileDescriptor/PollEvent.html">– PollEvent</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../../Time.html">Time</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Structs/Duration.html">Duration</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Structs/Deadline.html">Deadline</a>
              </li>
              <li class="nav-group-task">
                <a href="../../Extensions/Int.html">Int</a>
              </li>
            </ul>
          </li>
          <li class="nav-group-name">
            <a href="../../Errors.html">Errors</a>
            <ul class="nav-group-tasks">
              <li class="nav-group-task">
                <a href="../../Enums/VeniceError.html">VeniceError</a>
              </li>
            </ul>
          </li>
        </ul>
      </nav>
      <article class="main-content">
        <section>
          <section class="section">
            <h1>Group</h1>
              <div class="declaration">
                <div class="language">
                  <pre class="highlight"><code><span class="kd">public</span> <span class="kd">class</span> <span class="kt">Group</span></code></pre>

                </div>
              </div>
            <p>Coroutine groups are useful for canceling multiple coroutines at the
same time.</p>
<h2 id='example' class='heading'>Example:</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">group</span> <span class="o">=</span> <span class="kt">Coroutine</span><span class="o">.</span><span class="kt">Group</span><span class="p">(</span><span class="nv">minimumCapacity</span><span class="p">:</span> <span class="mi">2</span><span class="p">)</span>

<span class="k">try</span> <span class="n">group</span><span class="o">.</span><span class="n">addCoroutine</span> <span class="p">{</span>
    <span class="o">...</span>
<span class="p">}</span>

<span class="k">try</span> <span class="n">group</span><span class="o">.</span><span class="n">addCoroutine</span> <span class="p">{</span>
    <span class="o">...</span>
<span class="p">}</span>

<span class="c1">// all coroutines in the group will be canceled</span>
<span class="n">group</span><span class="o">.</span><span class="nf">cancel</span><span class="p">()</span>
</code></pre>

          </section>
          <section class="section task-group-section">
            <div class="task-group">
              <ul>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCC6Venice9Coroutine5GroupcFT15minimumCapacitySi_S1_"></a>
                    <a name="//apple_ref/swift/Method/init(minimumCapacity:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCC6Venice9Coroutine5GroupcFT15minimumCapacitySi_S1_">init(minimumCapacity:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Creates a new, empty coroutine group with at least the specified number
of elements&rsquo; worth of buffer.</p>

<p>Use this initializer to avoid repeated reallocations of a group&rsquo;s buffer
if you know you&rsquo;ll be adding elements to the group after creation. The
actual capacity of the created group will be the smallest power of 2 that
is greater than or equal to <code>minimumCapacity</code>.</p>
<h2 id='example' class='heading'>Example:</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">group</span> <span class="o">=</span> <span class="kt">CoroutineGroup</span><span class="p">(</span><span class="nv">minimumCapacity</span><span class="p">:</span> <span class="mi">2</span><span class="p">)</span>

<span class="k">try</span> <span class="n">group</span><span class="o">.</span><span class="n">addCoroutine</span> <span class="p">{</span>
    <span class="o">...</span>
<span class="p">}</span>

<span class="k">try</span> <span class="n">group</span><span class="o">.</span><span class="n">addCoroutine</span> <span class="p">{</span>
    <span class="o">...</span>
<span class="p">}</span>

<span class="c1">// all coroutines in the group will be canceled</span>
<span class="n">group</span><span class="o">.</span><span class="nf">cancel</span><span class="p">()</span>
</code></pre>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="nf">init</span><span class="p">(</span><span class="nv">minimumCapacity</span><span class="p">:</span> <span class="kt">Int</span> <span class="o">=</span> <span class="mi">0</span><span class="p">)</span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>minimumCapacity</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>The minimum number of elements that the
newly created group should be able to store without reallocating its
buffer.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCC6Venice9Coroutine5Group12addCoroutineFzT4bodyFzT_T__S0_"></a>
                    <a name="//apple_ref/swift/Method/addCoroutine(body:)" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCC6Venice9Coroutine5Group12addCoroutineFzT4bodyFzT_T__S0_">addCoroutine(body:)</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Creates a lightweight coroutine and adds it to the group.</p>
<h2 id='example' class='heading'>Example:</h2>
<pre class="highlight swift"><code><span class="k">let</span> <span class="nv">coroutine</span> <span class="o">=</span> <span class="k">try</span> <span class="n">group</span><span class="o">.</span><span class="n">addCoroutine</span> <span class="p">{</span>
    <span class="o">...</span>
<span class="p">}</span>
</code></pre>
<div class="aside aside-throws">
    <p class="aside-title">Throws</p>
    <p>The following errors might be thrown:</p>
<h4 id='veniceerror-canceledcoroutine' class='heading'>VeniceError.canceledCoroutine</h4>

<p>Thrown when the operation is performed within a canceled coroutine.</p>
<h4 id='veniceerror-outofmemory' class='heading'>VeniceError.outOfMemory</h4>

<p>Thrown when the system doesn&rsquo;t have enough memory to create a new coroutine.</p>

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">@discardableResult</span> <span class="kd">public</span> <span class="kd">func</span> <span class="nf">addCoroutine</span><span class="p">(</span><span class="nv">body</span><span class="p">:</span> <span class="kd">@escaping</span> <span class="p">()</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt">Void</span><span class="p">)</span> <span class="k">throws</span> <span class="o">-&gt;</span> <span class="kt"><a href="../../Classes/Coroutine.html">Coroutine</a></span></code></pre>

                        </div>
                      </div>
                      <div>
                        <h4>Parameters</h4>
                        <table class="graybox">
                          <tbody>
                            <tr>
                              <td>
                                <code>
                                <em>body</em>
                                </code>
                              </td>
                              <td>
                                <div>
                                  <p>Body of the newly created coroutine.</p>
                                </div>
                              </td>
                            </tr>
                          </tbody>
                        </table>
                      </div>
                      <div>
                        <h4>Return Value</h4>
                        <p>Newly created coroutine</p>
                      </div>
                    </section>
                  </div>
                </li>
                <li class="item">
                  <div>
                    <code>
                    <a name="/s:FCC6Venice9Coroutine5Group6cancelFT_T_"></a>
                    <a name="//apple_ref/swift/Method/cancel()" class="dashAnchor"></a>
                    <a class="token" href="#/s:FCC6Venice9Coroutine5Group6cancelFT_T_">cancel()</a>
                    </code>
                  </div>
                  <div class="height-container">
                    <div class="pointer-container"></div>
                    <section class="section">
                      <div class="pointer"></div>
                      <div class="abstract">
                        <p>Cancels all coroutines in the group.</p>
<div class="aside aside-warning">
    <p class="aside-title">Warning</p>
    Once a coroutine is canceled any coroutine-blocking operation within the coroutine
will throw <code><a href="../../Enums/VeniceError.html#/s:FO6Venice11VeniceError17canceledCoroutineFMS0_S0_">VeniceError.canceledCoroutine</a></code>.

</div>

                      </div>
                      <div class="declaration">
                        <h4>Declaration</h4>
                        <div class="language">
                          <p class="aside-title">Swift</p>
                          <pre class="highlight"><code><span class="kd">public</span> <span class="kd">func</span> <span class="nf">cancel</span><span class="p">()</span></code></pre>

                        </div>
                      </div>
                    </section>
                  </div>
                </li>
              </ul>
            </div>
          </section>
        </section>
        <section id="footer">
          <p>&copy; 2017 <a class="link" href="http://zewo.io" target="_blank" rel="external">Zewo</a>. All rights reserved. (Last updated: 2017-05-20)</p>
          <p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.8.1</a>, a <a class="link" href="http://realm.io" target="_blank" rel="external">Realm</a> project.</p>
        </section>
      </article>
    </div>
  </body>
</div>
</html>
